{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np # linear algebra\n",
    "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt  # Matlab-style plotting\n",
    "import seaborn as sns\n",
    "from scipy import stats\n",
    "from scipy.stats import norm, skew #for some statistics\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "text": [
      "H:\\Anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py:3057: DtypeWarning: Columns (5,10,14,15,16) have mixed types. Specify dtype option on import or set low_memory=False.\n  interactivity=interactivity, compiler=compiler, result=result)\n"
     ],
     "output_type": "stream"
    }
   ],
   "source": [
    "path=('H:/pythonchengx_u/ShuiDao/Data/')\n",
    "test = pd.read_csv(path+'testA.csv')\n",
    "train = pd.read_csv(path+'train_rice.csv',encoding='gbk')\n",
    "weather = pd.read_csv(path+'train_weather.csv',encoding='gbk')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "      区县id    2015年早稻    2016年早稻    2017年早稻    2015年晚稻    2016年晚稻    2017年晚稻\n0  county1  15.812589  15.878158  15.835681  15.754182  15.740001  15.636155\n1  county2  16.658008  16.623931  16.555916  16.666867  16.686079  16.583385\n2  county3  15.206326  15.085393  15.049788  15.177311  14.995996  14.889857\n3  county4  15.352061  15.311764  15.236604  15.020413  15.005488  14.882306\n4  county5  15.942749  15.943796  15.876010  16.019721  15.989249  15.905980",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>区县id</th>\n      <th>2015年早稻</th>\n      <th>2016年早稻</th>\n      <th>2017年早稻</th>\n      <th>2015年晚稻</th>\n      <th>2016年晚稻</th>\n      <th>2017年晚稻</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>county1</td>\n      <td>15.812589</td>\n      <td>15.878158</td>\n      <td>15.835681</td>\n      <td>15.754182</td>\n      <td>15.740001</td>\n      <td>15.636155</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>county2</td>\n      <td>16.658008</td>\n      <td>16.623931</td>\n      <td>16.555916</td>\n      <td>16.666867</td>\n      <td>16.686079</td>\n      <td>16.583385</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>county3</td>\n      <td>15.206326</td>\n      <td>15.085393</td>\n      <td>15.049788</td>\n      <td>15.177311</td>\n      <td>14.995996</td>\n      <td>14.889857</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>county4</td>\n      <td>15.352061</td>\n      <td>15.311764</td>\n      <td>15.236604</td>\n      <td>15.020413</td>\n      <td>15.005488</td>\n      <td>14.882306</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>county5</td>\n      <td>15.942749</td>\n      <td>15.943796</td>\n      <td>15.876010</td>\n      <td>16.019721</td>\n      <td>15.989249</td>\n      <td>15.905980</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "output_type": "execute_result",
     "execution_count": 3
    }
   ],
   "source": [
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [],
   "source": [
    "train['new'] = 0.1*train['2015年早稻']+0.2*train['2016年早稻']+0.7*train['2017年早稻']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [],
   "source": [
    "train[['区县id','new']].to_csv(path+'sub1_add_gradient2.csv',header=None,index=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [],
   "source": [
    "early = train[['区县id','2015年早稻','2016年早稻','2017年早稻']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [],
   "source": [
    "# weather_15_early.shape[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "       区县id  站名id    年份  月份  日期 日照时数（单位：h) 02时风向 08时风向 14时风向 20时风向  \\\n0  county25     1  2015   1   1        6.3   NNW     N   NNE     S   \n1  county25     1  2015   1   2        8.1   SSE     S   SSW     S   \n2  county25     1  2015   1   3        4.3     S   SSE     S   SSE   \n3  county25     1  2015   1   4          0   WNW   SSW     S   SSE   \n4  county25     1  2015   1   5          0   SSE     S   SSW     C   \n\n  日平均风速(单位：m/s) 日降水量（mm）  日最高温度（单位：℃）  日最低温度（单位：℃） 日平均温度（单位：℃） 日相对湿度（单位：%）  \\\n0           1.8        0         14.1          7.2         9.1          43   \n1           1.3        0         18.3          1.6         7.5          64   \n2             2        0         18.9          2.4         9.4          66   \n3           2.2      0.3         14.9          9.0        11.5          76   \n4           2.8      0.8         16.8         11.6        15.5          91   \n\n  日平均气压（单位：hPa）  \n0         980.6  \n1         977.7  \n2         973.1  \n3         966.7  \n4         963.9  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>区县id</th>\n      <th>站名id</th>\n      <th>年份</th>\n      <th>月份</th>\n      <th>日期</th>\n      <th>日照时数（单位：h)</th>\n      <th>02时风向</th>\n      <th>08时风向</th>\n      <th>14时风向</th>\n      <th>20时风向</th>\n      <th>日平均风速(单位：m/s)</th>\n      <th>日降水量（mm）</th>\n      <th>日最高温度（单位：℃）</th>\n      <th>日最低温度（单位：℃）</th>\n      <th>日平均温度（单位：℃）</th>\n      <th>日相对湿度（单位：%）</th>\n      <th>日平均气压（单位：hPa）</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>county25</td>\n      <td>1</td>\n      <td>2015</td>\n      <td>1</td>\n      <td>1</td>\n      <td>6.3</td>\n      <td>NNW</td>\n      <td>N</td>\n      <td>NNE</td>\n      <td>S</td>\n      <td>1.8</td>\n      <td>0</td>\n      <td>14.1</td>\n      <td>7.2</td>\n      <td>9.1</td>\n      <td>43</td>\n      <td>980.6</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>county25</td>\n      <td>1</td>\n      <td>2015</td>\n      <td>1</td>\n      <td>2</td>\n      <td>8.1</td>\n      <td>SSE</td>\n      <td>S</td>\n      <td>SSW</td>\n      <td>S</td>\n      <td>1.3</td>\n      <td>0</td>\n      <td>18.3</td>\n      <td>1.6</td>\n      <td>7.5</td>\n      <td>64</td>\n      <td>977.7</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>county25</td>\n      <td>1</td>\n      <td>2015</td>\n      <td>1</td>\n      <td>3</td>\n      <td>4.3</td>\n      <td>S</td>\n      <td>SSE</td>\n      <td>S</td>\n      <td>SSE</td>\n      <td>2</td>\n      <td>0</td>\n      <td>18.9</td>\n      <td>2.4</td>\n      <td>9.4</td>\n      <td>66</td>\n      <td>973.1</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>county25</td>\n      <td>1</td>\n      <td>2015</td>\n      <td>1</td>\n      <td>4</td>\n      <td>0</td>\n      <td>WNW</td>\n      <td>SSW</td>\n      <td>S</td>\n      <td>SSE</td>\n      <td>2.2</td>\n      <td>0.3</td>\n      <td>14.9</td>\n      <td>9.0</td>\n      <td>11.5</td>\n      <td>76</td>\n      <td>966.7</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>county25</td>\n      <td>1</td>\n      <td>2015</td>\n      <td>1</td>\n      <td>5</td>\n      <td>0</td>\n      <td>SSE</td>\n      <td>S</td>\n      <td>SSW</td>\n      <td>C</td>\n      <td>2.8</td>\n      <td>0.8</td>\n      <td>16.8</td>\n      <td>11.6</td>\n      <td>15.5</td>\n      <td>91</td>\n      <td>963.9</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "output_type": "execute_result",
     "execution_count": 8
    }
   ],
   "source": [
    "weather.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [],
   "source": [
    "weather_15 = weather[weather['年份']==2015]\n",
    "weather_16 = weather[weather['年份']==2016]\n",
    "weather_17 = weather[weather['年份']==2017]\n",
    "weather_18 = weather[weather['年份']==2018]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [],
   "source": [
    "weather_15_early = weather_15[weather_15['月份'].isin([4,5,6,7])]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [],
   "source": [
    "# weather.groupby([])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [],
   "source": [
    "df = pd.DataFrame([('bird', 'Falconiformes', 389.0),('bird', 'Psittaciformes', 24.0),('mammal', 'Carnivora', 80.2),('mammal', 'Primates', np.nan), ('mammal', 'Carnivora', 58)],index=['falcon', 'parrot', 'lion', 'monkey', 'leopard'],columns=('class', 'order', 'max_speed'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [],
   "source": [
    "grouped = df.groupby('class')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [],
   "source": [
    "grouped = df.groupby('order', axis='columns')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "   county1\n0  county2\n1  county3\n2  county4\n3  county5\n4  county6",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>county1</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>county2</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>county3</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>county4</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>county5</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>county6</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "output_type": "execute_result",
     "execution_count": 15
    }
   ],
   "source": [
    "test.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "source": [],
    "metadata": {
     "collapsed": false
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}